package com.ysqcould.web.controller.revita;


import com.ysqcould.Community.domain.Charity;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.revita.domain.GslNotice;
import com.ysqcould.revita.service.IGslNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 乡村轮播图Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/revita/notice")
public class GslNoticeController extends BaseController
{
    @Autowired
    private IGslNoticeService gslNoticeService;

    /**
     * 查询乡村轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('revita:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(GslNotice gslNotice)
    {
        startPage();
        List<GslNotice> list = gslNoticeService.selectGslNoticeList(gslNotice);
        return getDataTable(list);
    }

    /**
     * 导出乡村轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('revita:notice:export')")
    @Log(title = "乡村轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GslNotice gslNotice)
    {
        List<GslNotice> list = gslNoticeService.selectGslNoticeList(gslNotice);
        ExcelUtil<GslNotice> util = new ExcelUtil<GslNotice>(GslNotice.class);
        util.exportExcel(response, list, "乡村轮播图数据");
    }

    /**
     * 获取乡村轮播图详细信息
     */
    @PreAuthorize("@ss.hasPermi('revita:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gslNoticeService.selectGslNoticeById(id));
    }

    /**
     * 新增乡村轮播图
     */
    @PreAuthorize("@ss.hasPermi('revita:notice:add')")
    @Log(title = "乡村轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GslNotice gslNotice)
    {
        gslNotice.setAsId(getUserId());
        return toAjax(gslNoticeService.insertGslNotice(gslNotice));
    }

    /**
     * 修改乡村轮播图
     */
    @PreAuthorize("@ss.hasPermi('revita:notice:edit')")
    @Log(title = "乡村轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GslNotice gslNotice)
    {
        return toAjax(gslNoticeService.updateGslNotice(gslNotice));
    }

    /**
     * 删除乡村轮播图
     */
    @PreAuthorize("@ss.hasPermi('revita:notice:remove')")
    @Log(title = "乡村轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gslNoticeService.deleteGslNoticeByIds(ids));
    }


    /**
     * 状态修改
     */
    @Log(title = "消息通知", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody GslNotice notice)
    {
        return toAjax(gslNoticeService.updateStatus(notice));
    }

}
